#pragma once
#ifndef __IFRAME_TOOLS_H__
#define __IFRAME_TOOLS_H__

#include "IUtility.h"
#include "ISysResources.h"
#include "IIntProCom.h"
#include "IClient.h"
#include "IContainer.h"
#include "IThreadPoolManager.h"
#include "IPacket.h"

class IFrameTools
{
protected:
	IKernel * m_ptrKernel;

public:
	template< typename T >
	T * Instance(const char * pszClassName, const void * pvdParaVal = nullptr)
	{
		int iInstanceType = -1;
		T * ptrRetVal = nullptr;
		void * ptrInvok = m_ptrKernel->Invoke(pszClassName, pvdParaVal, nullptr, 0, iInstanceType, true);
		ptrRetVal = dynamic_cast<T *>(reinterpret_cast<IObject *>(ptrInvok));
		return ptrRetVal;
	}

    template< typename T >
    shared_ptr<T> Invok(const char * pszClassName, const void * pvdParaVal = nullptr)
    {
		int iInstanceType = -1;
        shared_ptr< T > ptrRetVal = nullptr;
        void * ptrInvok = m_ptrKernel->Invoke(pszClassName, pvdParaVal, nullptr, 0, iInstanceType, true);
        if (!ptrInvok) goto __end;
		ptrRetVal.reset(iInstanceType == 2 ? dynamic_cast<T *>(reinterpret_cast<IObject *>(ptrInvok)) :
			                                 dynamic_cast<T *>(reinterpret_cast<IObject *>(ptrInvok)), [](T * ptrObj) {}
		);
     __end:
        return ptrRetVal;
    }

public:
	virtual ~IFrameTools() { ; };
	virtual ILog & Log() = 0;
	virtual ISysFun & SysFun() = 0;
	virtual IStrFun & StrFun() = 0;
	virtual ILockSet & LockSet() = 0;
	virtual IGui & Gui() = 0;
	virtual IClient & Client() = 0;
	virtual IQueueOperation & QueueOperation() = 0;
	virtual IThreadManager & ThreadManager() = 0;
	virtual IInterProcessCommunication & IPC() = 0;
	virtual ITrigger * CreateTimer(const char * pszName) = 0;
	virtual ITrigger * CreateSmper(const char * pszName) = 0;
	virtual IData * CreateData(const char * pszBufer, const int iLen) = 0;
	virtual IPacket * CreateJsonPacket(const char * pszBufer, const int iLen) = 0;
	virtual ILock * CreateThreadLock() = 0;
	virtual ILock * CreateProcessLock(const char * pszName) = 0;
};

#endif//__IFRAME_TOOLS_H__
